package com.hyphenate.easeui.ui;

import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import com.hyphenate.easeui.R;

public class EaseShowVideoPreActivity extends EaseBaseActivity {

    private VideoView videoView;
    private ViewGroup containerTitle;

    private Uri fileUri;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.ease_showvideo_pre_activity);

        String filePath = getIntent().getStringExtra("filePath");
        if (TextUtils.isEmpty(filePath)) {
            Toast.makeText(this, "未找到视频文件", Toast.LENGTH_SHORT).show();
            finish();
            return;
        }

        containerTitle = findViewById(R.id.container_title);
        findViewById(R.id.container_back).setOnClickListener(v -> onBackPressed());

        fileUri = Uri.parse(filePath);

        videoView = findViewById(R.id.video);

        videoView.setVideoURI(fileUri);
        videoView.setMediaController(new MediaController(this) {
            @Override
            public void show() {
                super.show();
                containerTitle.setVisibility(VISIBLE);
            }

            @Override
            public void hide() {
                super.hide();
                containerTitle.setVisibility(GONE);
            }
        });

        videoView.setOnPreparedListener(mediaPlayer -> {
            videoView.start();
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        /*if(videoView!=null){
        }*/
    }
}
